package window;
/*
 * 飞机类
 */

import java.awt.*;
import java.awt.event.KeyEvent;

public class Plane extends GameOb {

    private boolean left, right, up, down;
    public boolean live=true;
    @Override
    public void drawself(Graphics g) {
        if (live) {
            g.drawImage(ima, (int)x, (int)y, null);
            if (left) {
                x -= speed;
            }
            if (right) {
                x += speed;
            }
            if (up) {
                y -= speed;
            }
            if (down) {
                y += speed;
            }
        }
    }

    public Plane(Image ima, int x, int y, int speed) {
        this.ima = ima;
        this.x = x;
        this.y = y;
        this.speed = speed;
        this.width = ima.getWidth(null) ;
        this.height = ima.getHeight(null);
    }

    public void addDirect(KeyEvent e) {
        switch (e.getKeyCode()) {
            case KeyEvent.VK_LEFT:
                left = true;
                break;
            case KeyEvent.VK_A:
                left = true;
                break;
            case KeyEvent.VK_DOWN:
                down = true;
                break;
            case KeyEvent.VK_S:
                down = true;
                break;
            case KeyEvent.VK_RIGHT:
                right = true;
                break;
            case KeyEvent.VK_D:
                right = true;
                break;
            case KeyEvent.VK_UP:
                up = true;
                break;
            case KeyEvent.VK_W:
                up = true;
                break;
        }
    }

    public void delDirect(KeyEvent e) {
        switch (e.getKeyCode()) {
            case KeyEvent.VK_LEFT:
                left = false;
                break;
            case KeyEvent.VK_A:
                left = false;
                break;
            case KeyEvent.VK_DOWN:
                down = false;
                break;
            case KeyEvent.VK_S:
                down = false;
                break;
            case KeyEvent.VK_RIGHT:
                right = false;
                break;
            case KeyEvent.VK_D:
                right = false;
                break;
            case KeyEvent.VK_UP:
                up = false;
                break;
            case KeyEvent.VK_W:
                up = false;
                break;
        }
    }
}
